package fserv;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import fserv.control.ClientController;
import fserv.ni.NetworkInterface;
import fserv.ui.ClientUI;

/**
 * Main class for the Chat System.
 * 
 * Initializes all the components of the Chat System and launches the GUI.
 * 
 * @author Arthur Bit-Monnot <abit@etud.insa-toulouse.fr>
 * @author Julien Marchand <jmarchan@etud.insa-toulouse.fr>
 */
public class Client {

    public static void main(String[] args) {
        try {
            /* Configure the Network Interface (required if multiple network
            interfaces are available) */
            NetworkInterface.setRemoteAddr(InetAddress.getByName("127.0.0.1"));

            // Initialize the Controller, the Network Interface and the GUI
            ClientController ctrl = ClientController.getInstance();
            NetworkInterface ni = NetworkInterface.getInstance();
            ClientUI ui = ClientUI.getInstance();

            // Set up the associations
            ctrl.setNI(ni);
            ctrl.setUI(ui);
            ui.setCtrl(ctrl);
            ni.setCtrl(ctrl);

			ctrl.launchNI();
			ui.show();
        } catch (UnknownHostException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}